import Mock from 'mockjs'

// 登录相关接口
Mock.mock('/api/admin/auth/login', 'post', (options) => {
  return {
    code: 200,
    message: '登录成功',
    data: {
      token: 'mock-token-xxxxxxxx',
      refreshToken: 'mock-refresh-token-xxxxxxxx',
      user: {
        id: 1,
        username: 'admin',
        nickname: '管理员',
        avatar: 'https://placeholder.pics/svg/100x100',
        roles: ['admin']
      }
    }
  }
})

// 获取当前用户信息
Mock.mock(RegExp('/api/admin/auth/current.*'), 'get', () => {
  return {
    code: 200,
    message: '获取成功',
    data: {
      id: 1,
      username: 'admin',
      nickname: '管理员',
      avatar: 'https://placeholder.pics/svg/100x100',
      roles: ['admin'],
      permissions: ['*']
    }
  }
})

// 登出接口
Mock.mock('/api/admin/auth/logout', 'post', () => {
  return {
    code: 200,
    message: '登出成功'
  }
})

// 仪表盘数据
Mock.mock(RegExp('/api/admin/dashboard/overview.*'), 'get', () => {
  return {
    code: 200,
    message: '获取成功',
    data: {
      totalOrders: Mock.Random.integer(100, 1000),
      totalSales: Mock.Random.float(10000, 100000, 2, 2),
      totalProducts: Mock.Random.integer(50, 500),
      totalUsers: Mock.Random.integer(100, 2000)
    }
  }
})

// 销售统计
Mock.mock(RegExp('/api/admin/dashboard/sales-stats.*'), 'get', () => {
  const dates = []
  const sales = []
  const orders = []
  
  for (let i = 0; i < 7; i++) {
    dates.push(Mock.Random.date('MM-dd'))
    sales.push(Mock.Random.float(1000, 10000, 2, 2))
    orders.push(Mock.Random.integer(10, 100))
  }
  
  return {
    code: 200,
    message: '获取成功',
    data: {
      dates,
      sales,
      orders
    }
  }
})

// 最新订单
Mock.mock(RegExp('/api/admin/dashboard/latest-orders.*'), 'get', () => {
  const orders = []
  for (let i = 0; i < 10; i++) {
    orders.push({
      id: Mock.Random.id(),
      orderNo: Mock.Random.string('number', 8),
      user: Mock.Random.cname(),
      amount: Mock.Random.float(100, 1000, 2, 2),
      status: Mock.Random.integer(0, 3),
      createTime: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss')
    })
  }
  
  return {
    code: 200,
    message: '获取成功',
    data: orders
  }
})

// 商品分类列表
Mock.mock(RegExp('/api/admin/categories.*'), 'get', (options) => {
  const categories = []
  for (let i = 0; i < 10; i++) {
    categories.push({
      id: i + 1,
      name: `分类${i + 1}`,
      sort: i * 10,
      status: Mock.Random.integer(0, 1),
      create_time: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss'),
      update_time: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss')
    })
  }
  
  return {
    code: 200,
    message: '获取成功',
    data: {
      list: categories,
      total: 20
    }
  }
})

// 商品列表
Mock.mock(RegExp('/api/admin/products.*'), 'get', () => {
  const products = []
  for (let i = 0; i < 10; i++) {
    products.push({
      id: i + 1,
      name: `商品${i + 1}`,
      categoryId: Mock.Random.integer(1, 5),
      categoryName: `分类${Mock.Random.integer(1, 5)}`,
      price: Mock.Random.float(10, 1000, 2, 2),
      stock: Mock.Random.integer(0, 999),
      sales: Mock.Random.integer(0, 500),
      status: Mock.Random.integer(0, 1),
      images: [Mock.Random.image('200x200', '#50B347', '#FFF', 'Mock')],
      create_time: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss'),
      update_time: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss')
    })
  }
  
  return {
    code: 200,
    message: '获取成功',
    data: {
      list: products,
      total: 100
    }
  }
})

// 轮播图列表
Mock.mock(RegExp('/api/admin/banners.*'), 'get', () => {
  const banners = []
  for (let i = 0; i < 5; i++) {
    banners.push({
      id: i + 1,
      title: `轮播图${i + 1}`,
      image: Mock.Random.image('750x400', '#4A7BF7', '#FFF', 'Banner'),
      link: `/pages/product/detail?id=${Mock.Random.integer(1, 20)}`,
      sort: i,
      status: Mock.Random.integer(0, 1),
      create_time: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss'),
      update_time: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss')
    })
  }
  
  return {
    code: 200,
    message: '获取成功',
    data: {
      list: banners,
      total: 5
    }
  }
})

// 轮播图上传
Mock.mock(RegExp('/api/admin/upload/banner'), 'post', () => {
  return {
    code: 200,
    message: '上传成功',
    data: {
      url: Mock.Random.image('750x400', '#4A7BF7', '#FFF', 'Upload')
    }
  }
})

export default Mock 